package com.seed.core.query.pojo;

import com.seed.core.enumeration.Direction;
import com.seed.core.enumeration.PropertyType;
import com.seed.core.pojo.seed.*;

import java.util.LinkedHashMap;

public class Ordered extends LinkedHashMap<String, Ordered> {
    private PropertyType type;
    private Property property;
    private Direction value;

    public Ordered(PropertyType type) {
        this.type = type;
    }

    public Ordered(PropertyType type, Direction value) {
        this(type);
        this.value = value;
    }

    public Ordered(Property property) {
        this.property = property;
        if(property instanceof Habtms) this.type = PropertyType.habtm;
        else if(property instanceof HasManys) this.type = PropertyType.hasMany;
        else if(property instanceof HasOnes) this.type = PropertyType.hasOne;
        else if(property instanceof BelongsTos) this.type = PropertyType.belongsTo;
        else this.type = PropertyType.column;
    }

    public Ordered(Property property, Direction value) {
        this(property);
        this.value = value;
    }

    public static Ordered of(Property property) {
        return new Ordered(property);
    }

    public static Ordered of(Property property, Direction value) {
        return new Ordered(property, value);
    }

    public PropertyType getType() {
        return type;
    }

    public void setType(PropertyType type) {
        this.type = type;
    }

    public Property getProperty() {
        return property;
    }

    public void setProperty(Property property) {
        this.property = property;
    }

    public Direction getValue() {
        return value;
    }

    public void setValue(Direction value) {
        this.value = value;
    }
}
